<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>UuidValidator</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../css/github.css" type="text/css" media="screen" />
<script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>
    <div class="banner">
        <h1>
            <span class="type">Class</span>
            UuidValidator
                <span class="parent">&lt;
                    ActiveModel::EachValidator
                </span>
        </h1>
        <ul class="files">
            <li><a href="../files/lib/hoodoo/active/active_model/uuid_validator_rb.html">lib/hoodoo/active/active_model/uuid_validator.rb</a></li>
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
    <div class="description">
      
<p>Provides simple UUID validation via an ActiveModel::EachValidator. Uuid is
not capitalised as ActiveModel&#39;s “magic” cannot find the validator if
it is.</p>

    </div>








    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
        <dt>V</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-i-validate_each">validate_each</a>
              </li>
          </ul>
        </dd>
    </dl>










    <!-- Methods -->
      <div class="sectiontitle">Instance Public methods</div>
        <div class="method">
          <div class="title method-title" id="method-i-validate_each">
              <b>validate_each</b>( record, attribute, value )
            <a href="../classes/UuidValidator.html#method-i-validate_each" name="method-i-validate_each" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Any field this validator is applied to is considered valid if it is
<code>nil</code> or a valid UUID. In the case of UUIDs which should not be
nil, a separate validation must be added.</p>

<p>Example:</p>

<pre><code>class SomeModel &lt; ActiveRecord::Base

  validates :somefield, uuid: true
end
</code></pre>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-validate_each_source')" id="l_method-i-validate_each_source">show</a>
              </p>
              <div id="method-i-validate_each_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/active/active_model/uuid_validator.rb, line 33</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">validate_each</span>( <span class="ruby-identifier">record</span>, <span class="ruby-identifier">attribute</span>, <span class="ruby-identifier">value</span> )

  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-constant">Hoodoo</span><span class="ruby-operator">::</span><span class="ruby-constant">UUID</span>.<span class="ruby-identifier">valid?</span>( <span class="ruby-identifier">value</span> )
    <span class="ruby-identifier">record</span>.<span class="ruby-identifier">errors</span>[ <span class="ruby-identifier">attribute</span> ] <span class="ruby-operator">&lt;&lt;</span> ( <span class="ruby-identifier">options</span>[ <span class="ruby-value">:message</span> ] <span class="ruby-operator">||</span> <span class="ruby-string">&#39;is invalid&#39;</span> )
  <span class="ruby-keyword">end</span>

<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
</div>

    </div>
  </body>
</html>
